﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.ButtonBLL;

namespace Tauren.Business.Core.Controllers
{
    /// <summary>
    /// 按钮信息接口
    /// </summary>
    [Route("api/btns"), ApiVersion("1.0")]
    [ApiController]
    public class ButtonsController : ControllerBase
    {
        private IButtonService service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_service"></param>
        public ButtonsController(IButtonService _service)
        {
            service = _service;
        }
        /// <summary>
        /// 分页获取 账号信息列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/pages")]
        public IActionResult Pages([FromBody] Entity.Global.QueryModel queryModel) => service.Pages(queryModel).ToJsonResult(true);
        /// <summary>
        /// 根据主键获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/get/{id}")]
        public IActionResult Get([FromRoute] long id) => service.Get(AutoID: id).ToJsonResult();

        [HttpPost, Route("v{version:apiVersion}/add")]
        public IActionResult Add([FromBody] Entity.Input.Button_Input data) => service.Insert(data).ToJsonResult();

        /// <summary>
        /// 根据主键删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del/{id}")]
        public IActionResult Delete([FromRoute] long id) => service.PhysicallyDeleted(AutoID: id).ToJsonResult(true);

        /// <summary>
        /// 获取Config数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/config/{type}")]
        public IActionResult Config([FromRoute] string type) => service.Config(type).ToJsonResult(true);

        /// <summary>
        /// 获取列表模板数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/template/{key}")]
        public IActionResult Template([FromRoute]string key) => service.Template(key).ToJsonResult(true);

        /// <summary>
        /// 更新数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/edit")]
        public IActionResult Edit([FromBody] Entity.Input.Button_Input data) => service.Edit(data).ToJsonResult(true);


    }
}
